home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Quaternary Source / KeyUtils.cpp < prev    next >
Text File  |  1995-11-08  |  1KB  |  67 lines

  1. /*
  2.     KeyUtils.c++
  3.     Written by Hiep Dam.
  4.     Last Update: Sept. 1994
  5. */
  6. #include "KeyUtils.h"
  7.  
  8. Boolean IsKeyDown(unsigned short theKey);
  9. Boolean IsKeyDown(unsigned short theKey)
  10. // theKey =  any keyboard scan code, 0-127
  11. {
  12.     unsigned char km[16];
  13.  
  14.     GetKeys(*((KeyMap*) &km));
  15.     return ((km[theKey>>3] >> (theKey & 7)) & 1);
  16. }
  17.  
  18. Boolean CmdKeyDown() {
  19.     return IsKeyDown(0x37);
  20. }
  21.  
  22. Boolean OptionKeyDown() {
  23.     return IsKeyDown(0x3A);
  24. }
  25.  
  26. Boolean ShiftKeyDown() {
  27.     return IsKeyDown(0x38);
  28. }
  29.  
  30. Boolean CapsKeyDown() {
  31.     return IsKeyDown(0x39);
  32. }
  33.  
  34. Boolean ControlKeyDown() {
  35.     return IsKeyDown(0x3B);
  36. }
  37.  
  38. Boolean SpaceKeyDown() {
  39.     return IsKeyDown(0x31);
  40. }
  41.  
  42. Boolean TabKeyDown() {
  43.     return IsKeyDown(0x30);
  44. }
  45.  
  46. // ---------------------------------------------------------------------------
  47.  
  48. Boolean StrNumberOnly(Str255 theStr, Boolean includePeriod, Boolean includeComma) {
  49.     Boolean numOnly = true;
  50.     
  51.     for (short i = 1; i <= theStr[0]; i++) {
  52.         if (theStr[i] >= '0' && theStr[i] <= '9') {
  53.         }
  54.         else if (includePeriod && theStr[i] == '.') {
  55.         }
  56.         else if (includeComma && theStr[i] == ',') {
  57.         }
  58.         else if (theStr[i] == '+' || theStr[i] == '-') {
  59.         }
  60.         else {
  61.             numOnly = false;
  62.             break;
  63.         }
  64.     }
  65.  
  66.     return(numOnly);
  67. } // END StrNumberOnly